package com.fimmlps.reronge.dto;

import com.fimmlps.reronge.entity.EntryUser;
import com.fimmlps.reronge.entity.EntryUserChat;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.time.LocalDateTime;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class FriendDto {
    //好友ID 好友名
    private int userId;

    private String userName;

    private String headUrl;

    private LocalDateTime latestTime;

    private String latestMessage;

    public FriendDto(EntryUser user, EntryUserChat chat){
        userId = user.getUserId();
        userName = user.getUserName();
        headUrl = user.getUserHeadUrl();
        if(chat==null){
            latestTime = LocalDateTime.MIN;
            latestMessage = "No Message";
        }
        else{
            latestTime = chat.getCreateTime();
            latestMessage = chat.getChatContent();
        }
    }
}
